2023-11-27


Array buffer encoding, decoding to strings
I had a problem where I couldn’t return an array buffer (binary data) in a SvelteKit load function. You can only return POJOs. The solution is simple though - stringify when encoding and parse when decoding!
// Load function
const stringifiedImage = JSON.stringify(Array.from(new Uint8Array(image)));

return {
  stringifiedImage
}
// +page.svelte

export let data;
const parsedImage = JSON.parse(data.stringifiedImage);
Easy!
Go back to all posts

2023-10-14


Go back to all posts

2023-10-11


Go back to all posts